import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
// import NotFound from '@/views/exception/Excep404.vue'
// import ServerError from '@/views/exception/Excep500.vue'

// import Forbidden from '@/views/exception/Excep403.vue'
import 'nprogress/nprogress.css'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    hideMenu: true,
    component: () => import(/* webpackChunkName: "Login" */ '../view/Login.vue'),
  },
  //下面是注册的部分
  {
    path: '/register',
    name: 'register',
    hideMenu: true,
    component: () => import(/* webpackChunkName: "Register" */ '../view/Register.vue'),

  },
  //下面是找回密码的部分
  {
    path: '/forgetpwd',
    name: 'forgetPwd',
    hideMenu: true,
    component: () => import(/* webpackChunkName: "ForgetPwd" */ '../view/ForgetPwd.vue'),
  },
  //下面是主页管理
  {
    path: '/',
    component: () => import(/* webpackChunkName: "Home" */ '../view/home/Home.vue'),
    name: 'Home',
    meta: {
      icon: 'form',
      title: '主页',
    },
    children: [
      //下面是用户管理
      {
        path: '/user',
        component: () => import(/* webpackChunkName: "UserManagement" */ '../view/share/UserManagement.vue'),
        meta: {
          icon: 'form',
          title: '用户管理',
        },
      },
      //下面是权限管理
      {
        path: '/auth',
        component: { render: h => h('router-view') },
        children: [
          {
            path: '/auth/button',
            component: () => import(/* webpackChunkName: "ButtonManagement" */ '../view/share/ButtonManagement.vue'),
            meta: {
              icon: 'form',
              title: '按钮管理',
            },
          },
          {
            path: '/auth/menu',
            component: () => import(/* webpackChunkName: "MenuManagement" */ '../view/share/MenuManagement.vue'),
            meta: {
              icon: 'form',
              title: '菜单管理',
            },
          },
          {
            path: '/auth/role',
            component: () => import(/* webpackChunkName: "RolesManagement" */ '../view/share/RolesManagement.vue'),
            meta: {
              icon: 'form',
              title: '角色管理',
            },
          },
        ]
      },
      //下面是系统管理
      {
        path: '/sys',
        component: { render: h => h('router-view') },
        children: [
          {
            path: '/sys/param',
            component: () => import(/* webpackChunkName: "ParameterManagement" */ '../view/share/ParameterManagement.vue'),
            name: 'ParameterManagement',
            meta: {
              icon: 'form',
              title: '系统参数',
            },
          },
          {
            path: '/sys/dict',
            component: () => import(/* webpackChunkName: "DataDictionary" */ '../view/share/DataDictionary.vue'),
            name: 'DataDictionary',
            meta: {
              icon: 'form',
              title: '数据字典',
            },
          },
          {
            path: '/sys/organ',
            component: () => import(/* webpackChunkName: "OrganizationalManagement" */ '../view/share/OrganizationalManagement.vue'),
            name: 'OrganizationalManagement',
            meta: {
              icon: 'form',
              title: '机构管理',
            },
          },
        ]
      },
      //下面是班课管理
      {
        path: '/class',
        component: () => import(/* webpackChunkName: "MyCourseList" */ '../view/share/MyCourseList.vue'),
        name: 'course',
        meta: {
          icon: 'form',
          title: '班课管理',
        },
      },

      //下面是课程管理
      {
        path: '/course',
        component: () => import(/* webpackChunkName: "Course" */ '../view/share/Course.vue'),
        name: 'course',
        meta: {
          icon: 'form',
          title: '课程管理',
        },
      },

      //下面是异常管理
      {
        path: '/except',
        component: { render: h => h('router-view') },
        children: [
          {
            path: '/except/401',
            component: () => import(/* webpackChunkName: "Excep401" */ '../view/exception/Excep401.vue'),
            name: 'Exception401',
            meta: {
              icon: 'form',
              title: '401错误',
            },
          },
          {
            path: '/except/403',
            component: () => import(/* webpackChunkName: "Excep403" */ '../view/exception/Excep403.vue'),
            name: 'Exception403',
            meta: {
              icon: 'form',
              title: '403错误',
            },
          },
          {
            path: '/except/404',
            component: () => import(/* webpackChunkName: "Excep404" */ '../view/exception/Excep404.vue'),
            name: 'Exception404',
            meta: {
              icon: 'form',
              title: '404错误',
            },
          },
          {
            path: '/except/500',
            component: () => import(/* webpackChunkName: "Excep500" */ '../view/exception/Excep500.vue'),
            name: 'Exception500',
            meta: {
              icon: 'form',
              title: '500错误',
            },
          },
        ]
      },

      //下面是个人信息管理
      {
        path: '/person',
        component: () => import(/* webpackChunkName: "Person" */ '../view/share/Person.vue'),
        meta: {
          icon: 'form',
          title: '个人信息管理'
        },
      },
      //下面这些不能放在children里面，没设置router-view

      {
        path: '/course/task',
        component: () => import(/* webpackChunkName: "TaskManagement" */ '../view/share/TaskManagement.vue'),
        meta: {
          icon: 'form',
          title: '任务管理',
        },
      },
      {
        path: '/course/task/clockin',
        component: () => import(/* webpackChunkName: "ClockinManagement" */ '../view/share/ClockinManagement.vue'),
        meta: {
          icon: 'form',
          title: '签到信息管理',
        },
      },
      {
        path: '/sys/organ/add',
        component: () => import(/* webpackChunkName: "AddCollege" */ '../view/share/AddCollege.vue'),
        name: 'AddCollege',
        meta: {
          icon: 'form',
          title: '添加学院',
        },
      },
      {
        path: '/sys/dict/add',
        component: () => import(/* webpackChunkName: "AddDataDictionary" */ '../view/share/AddDataDictionary.vue'),
        name: 'AddDataDictionary',
        meta: {
          icon: 'form',
          title: '添加数据字典',
        },
      },
      {
        path: '/sys/dict/info',
        component: () => import(/* webpackChunkName: "CheckDataDictionaryInfo" */ '../view/share/CheckDataDictionaryInfo.vue'),
        name: 'CheckDataDictionaryInfo',
        meta: {
          icon: 'form',
          title: '查看数据字典明细',
        },
      },
      {
        path: '/auth/role/warrant',
        component: () => import(/* webpackChunkName: "Warrant" */ '../view/share/Warrant.vue'),
        name: 'Warrant',
        meta: {
          icon: 'form',
          title: '授予权限',
        },
      },
      {
        path: '/user/role',
        component: () => import(/* webpackChunkName: "UserAuth" */ '../view/share/UserAuth.vue'),
        name: 'UserAuth',
        meta: {
          icon: 'form',
          title: '授予角色',
        },
      },
      {
        path: '/',
        name: '欢迎页',
        component: () => import(/* webpackChunkName: "Welcome" */ '../components/Welcome.vue'),
      },
      {
        path: '/*',
        name: '404',
        component: () => import(/* webpackChunkName: "Excep404" */ '../view/exception/Excep404.vue'),
      },
    ]
  },
]

const router = new VueRouter({
  routes
})


//挂载路由导航守卫
// 路由导航守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('auth_token')
  // if (to.meta.notPermission) {
  //   next('/user')
  // };
  NProgress.start()

  if (to.path !== '/login' && !token && to.path !== '/register' && to.path !== '/forgetpwd') {
    next('/login')
  } else {
    next()
  }
})

router.afterEach(() => {
  NProgress.done()
})


export default router
